﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using HumanResorcesProj.GUI;
using HumanResorcesProj.BLL;
using System.Web.UI.WebControls;
using System.Collections;

namespace HumanResorcesProj.GUI
{
    public partial class AddNewEmployee : System.Web.UI.Page
    {

        public static string SubProj = null;
        protected void Page_Load(object sender, EventArgs e)
        {
           //InsertButton btnSubmit.Attributes.Add("onclick", "javascript:if(confirm('Are you sure everything is correct?')== false) return false;");
        }




        public void fillSubprojddl()
        {

            AssoDomainBLL bll = new AssoDomainBLL();

            DAL._HR_DS.AssoDomainDataTable SubProj;
            DropDownList ddl1 = new DropDownList();
            ddl1 = (DropDownList) FormView1.FindControl("DropDownList8");
            SubProj = bll.GetSubProj(ddl1.SelectedValue);

            ArrayList Name = new ArrayList();
            
            //Hashtable Name = new Hashtable();
            
            Name.Add(Convert.ToString(SubProj[0][4]));
            for (int i = 1; SubProj.Rows.Count > i; i++)
            {
              
                bool check = true;
                for (int j = 0; Name.Count > j; j++)
                {
                    string proj = Convert.ToString(SubProj[i][4]);
                    if(Name[j].Equals(proj))
                    {
                        check = false;
                       
                    }
                   
                    
                }
                if (check) Name.Add(Convert.ToString(SubProj[i][4]));
            }
            DropDownList ddl = new DropDownList();
            ddl = (DropDownList) FormView1.FindControl("DropDownList7");
            ddl.DataSource = Name;
            ddl.DataTextField = null;
            ddl.DataValueField = null;
            ddl.DataBind();


        }

        protected void InsertCancelButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("MainWindow.aspx");
        }

        protected void chButton_Click(object sender, EventArgs e)
        {
            string url = "Extensions/AddNewChild.aspx?ID=1&cat=test";
            string fullURL = "window.open('" + url + "', '_blank', 'height=500,width=800,status=yes,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,titlebar=no' );";
            ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", fullURL, true);

        }

        protected void InsertButton_Click(object sender, EventArgs e)
        {// check it out
         //   string test = FormView1.FindControl("EmpNameTextBox").ToString() ;
            //if (test == "shady")
            {
            

            }
        }

        protected void FeedBackTalksButton_Click(object sender, EventArgs e)
        {
            string url = "Extensions/FeedBackTalks.aspx?ID=1&cat=test";
            string fullURL = "window.open('" + url + "', '_blank', 'height=500,width=800,status=yes,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,titlebar=no' );";
            ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", fullURL, true);

        }

        protected void UploadFileButton_Click(object sender, EventArgs e)
        {
            string url = "Extensions/UploadFile.aspx?ID=1&cat=test";
            string fullURL = "window.open('" + url + "', '_blank', 'height=500,width=800,status=yes,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,titlebar=no' );";
            ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", fullURL, true);

        }

        protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
            Emp BLL = new Emp();
            try
            {
                if (BLL.UserGetByName(args.Value).Rows.Count > 0)
                   args.IsValid = false;
                 else
                   args.IsValid = true;
                
            }
            finally
            {
                //TODO: Dispose
            }
        }

        protected void ValidIDValidator_ServerValidate(object source, ServerValidateEventArgs args)
        {
            int[] arr = new int[9];
                    int IDTest = Convert.ToInt32(args.Value);
                                       
                    for (int i = 8; i >= 0 ; i--)
                    {
                        arr[i] = IDTest % 10;
                        IDTest = IDTest / 10;
                    }
                    
                    int[] arr2 = new int[9];
                    int Sum = 0;
                    int temp;
                    for (int i = 0; i < 9; i++)
                    {
                        if ((i % 2) == 1)
                        {
                            temp = 2 * arr[i];
                            if (temp <= 9)
                                arr2[i] = temp;
                            else switch (temp)
                                {
                                    case 10: arr2[i] = 1;
                                        break;
                                    case 12: arr2[i] = 3;
                                        break;
                                    case 14: arr2[i] = 5;
                                        break;
                                    case 16: arr2[i] = 7;
                                        break;
                                    case 18: arr2[i] = 9;
                                        break;
                                }
                        }
                        else arr2[i] = arr[i];
                        Sum = Sum + arr2[i];

                    }
                    
                    if (Sum % 10 == 0) args.IsValid = true;
                    else args.IsValid = false;
        }

        protected void DropDownList8_SelectedIndexChanged(object sender, EventArgs e)
        {
            fillSubprojddl();
        }

        protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
        {

            DropDownList ddl = new DropDownList();
            ddl = (DropDownList)FormView1.FindControl("DropDownList7");
            SubProj = ddl.SelectedValue;
        }

       
        

        

        

        

        

        

        
        



        

        


        

        
    }
}
